<template>
  <div class="h-full flex flex-col">
    <a-menu
      mode="horizontal"
      type="inner"
      class="bg-[#f0f2f5] mb-2"
      v-model="menuKey"
      @click="handleClickMenu"
      style="position: relative"
    >
      <a-menu-item :key="1"
        >{{ $t("menu.ren") }}
        <span style="color: red">
          {{ tabTotal[0] > 0 ? tabTotal[0] : "" }}</span
        >
      </a-menu-item>
      <a-menu-item :key="2"
        >{{ $t("menu.dashboard") }}
        <span style="color: red">
          {{ tabTotal[1] > 0 ? tabTotal[1] : "" }}</span
        >
      </a-menu-item>
      <a-menu-item :key="3" v-if="ifAllTask"
        >{{ $t("menu.dashboard.analysis")
        }}<span style="color: red">
          {{ tabTotal[2] > 0 ? tabTotal[2] : "" }}</span
        >
      </a-menu-item>
    </a-menu>
    <!--    <a-card>-->
    <!--      <a-form layout="inline" v-model="queryForm">-->
    <!--        <a-form-item>-->
    <!--          <a-input-->
    <!--              v-model="queryForm.Name"-->
    <!--              :placeholder="$t('menu.dashboard.monitor')"-->
    <!--          />-->
    <!--        </a-form-item>-->
    <!--        <a-form-item>-->
    <!--          <a-select-->
    <!--              v-model="queryForm.taskType"-->
    <!--              :placeholder="$t('menu.dashboard.workplace')"-->
    <!--              style="width: 178px"-->
    <!--              allowClear-->
    <!--              option-filter-prop="children"-->
    <!--              :filter-option="filterOption"-->
    <!--              show-search-->
    <!--          >-->
    <!--            &lt;!&ndash; <a-select-option :value="0">未确认</a-select-option> &ndash;&gt;-->
    <!--            <a-select-option :value="1">Dpia</a-select-option>-->
    <!--            <a-select-option :value="2">Risk</a-select-option>-->
    <!--            <a-select-option :value="3">Action</a-select-option>-->
    <!--          </a-select>-->
    <!--        </a-form-item>-->
    <!-- 负责人 -->
    <!--        <a-form-item>-->
    <!--          <a-select-->
    <!--              :placeholder="$t('menu.form')"-->
    <!--              v-model="queryForm.Owner"-->
    <!--              style="width: 160px"-->
    <!--              allowClear-->
    <!--              option-filter-prop="children"-->
    <!--              :filter-option="filterOption"-->
    <!--              @search="filte1rOption"-->
    <!--              show-search-->
    <!--              @change="onChange"-->
    <!--          >-->
    <!--            <a-select-option-->
    <!--                v-for="item in userList"-->
    <!--                :value="item.value"-->
    <!--                :key="item.value"-->
    <!--            >-->
    <!--              {{ item.label }}-->
    <!--            </a-select-option>-->
    <!--          </a-select>-->
    <!--        </a-form-item>-->
    <!--        <a-form-item>-->
    <!--          <a-button-->
    <!--              :disabled="!queryForm.taskType"-->
    <!--              type="primary"-->
    <!--              icon="search"-->
    <!--              @click="search"-->
    <!--          >{{ $t("menu.form.basic-form") }}-->
    <!--          </a-button>-->
    <!--        </a-form-item>-->
    <!--        <a-form-item>-->
    <!--          <a-button-->
    <!--              icon="reload"-->
    <!--              @click="-->
    <!--              () => {-->
    <!--                (queryForm = {}), getList1();-->
    <!--              }-->
    <!--            "-->
    <!--          >{{ $t("menu.form.step-form") }}-->
    <!--          </a-button>-->
    <!--        </a-form-item>-->
    <!--      </a-form>-->
    <!--    </a-card>-->

    <!-- 列表 -->
    <a-card class="mt-[10px]">
      <creatRiskAction :mode="mode" :riskId="riskId" :editId="editId" 
      ref="creatRiskAction" @getList="getList" @succeed="getList">
      </creatRiskAction>
      <a-table
        size="middle"
        class="h-full overflow-x-auto"
        :data-source="listData"
        @change="tableChange"
        :pagination="false"
        :rowKey="(record) => record.Id"
        @expand="getRiskList"
        :expanded-row-keys.sync="expandedRowKeys"
        :loading="listLoading"
      >
        <template slot="expandedRowRender" slot-scope="precord, text">
          <a-table
            :pagination="false"
            size="middle"
            style="margin-top: 20px"
            class="h-full overflow-x-auto"
            :dataSource="riskList"
            :rowKey="(record) => record.Id"
          >
            <!-- Action Name -->
            <a-table-column
              key="DpiaActionName"
              width="150px"
              :customRender="
                (_, record) => {
                  return record.DpiaActionName || record.DpiaActionIdTag;
                }
              "
            >
              <span slot="title">{{
                $t("user.verification-code.required111566166")
              }}</span>
            </a-table-column>
            <!-- Source -->
            <a-table-column
              key="DpiaActionSource"
              data-index="DpiaActionSource"
              width="150"
            >
              <span slot="title">{{
                $t("user.verification-code.required111566167")
              }}</span>
            </a-table-column>
            <!-- Action Result -->
            <a-table-column
              key="DpiaActionResult"
              data-index="DpiaActionResult"
              width="150"
            >
              <span slot="title">{{
                $t("user.verification-code.required1115661688888")
              }}</span>
            </a-table-column>
            <!-- Action Owner -->
            <a-table-column
              key="DpiaActionUserResponsible"
              data-index="DpiaActionUserResponsible"
              width="150"
            >
              <span slot="title">{{
                $t("user.verification-code.required1115661281111")
              }}</span>
            </a-table-column>
            <!-- Creation Time -->
            <a-table-column
              key="DpiaActionCreatetime"
              data-index="DpiaActionCreatetime"
              width="150"
            >
              <span slot="title">{{
                $t("user.verification-code.required111566169")
              }}</span>
            </a-table-column>
            <!-- Due Date -->
            <a-table-column
              key="DpiaActionFinishTime"
              data-index="DpiaActionFinishTime"
              width="150"
            >
              <span slot="title">{{
                $t("user.verification-code.required111566170")
              }}</span>
            </a-table-column>
            <!-- 状态 -->
            <a-table-column
              key="DpiaActionStatus"
              :title="$t('user.login.message-invalid-verification-code0011')"
            >
              <template slot-scope="text, record">
                <span>
                  <div v-if="record.DpiaActionStatus == 1">
                    <a-badge color="blue" />
                    {{ $t("user.verification-code.required111566133") }}
                  </div>
                  <div v-else-if="record.DpiaActionStatus == 3">
                    <a-badge color="purple" />
                    {{ $t("user.verification-code.required1115661455555") }}
                  </div>
                  <div v-else-if="record.DpiaActionStatus == 4">
                    <a-badge color="green" />
                    {{ $t("user.verification-code.required111566146") }}
                  </div>
                  <div v-else-if="record.DpiaActionStatus == 5">
                    <a-badge color="grey" />
                    {{
                      $t(
                        "user.verification-code.required111566110577371442281431222335566555555"
                      )
                    }}
                  </div>
                </span>
              </template>
            </a-table-column>
            <a-table-column
              key="action"
              :title="$t('app.setting.othersettings')"
              style="margin-left: -15px"
            >
              <template slot-scope="text, record">
                <span>
                  <a-space size="0">
                    <!-- 修改按钮 -->
                    <a-button
                      type="link"
                      @click="showModal('1', record.Id, record.state, record)"
                      block
                      v-if="
                        ((precord.DpiaDcoUserId === userId ||
                          precord.RiskOwnerUserId === userId) &&
                          (precord.DpiaStatus === 4 ||
                            precord.DpiaStatus === 2 ||
                            precord.DpiaStatus === 3 ||
                            precord.RiskState === 3)) ||
                        (precord.DpiaDcoUserId !== userId &&
                          precord.RiskOwnerUserId !== userId &&
                          record.DpiaActionUserId === userId &&
                          precord.DpiaStatus === 4)
                      "
                      >{{
                        $t("user.verification-code.required111566147")
                      }}</a-button
                    >
                    <!-- 删除按钮 -->
                    <a-popconfirm
                      :title="
                        $t('user.verification-code.required111566110577225')
                      "
                      :ok-text="$t('user.verification-code.required1166')"
                      :cancel-text="$t('user.email.required11')"
                      @confirm="delActions(record.Id)"
                      v-if="
                        precord.DpiaDcoUserId &&
                        (precord.DpiaDcoUserId === userId ||
                          precord.DpiaDcoUserId === RiskOwnerUserId) &&
                        (precord.DpiaStatus === 2 ||
                          precord.DpiaStatus === 3 ||
                          precord.RiskState === 2 ||
                          precord.RiskState === 3)
                      "
                    >
                      <a-button type="link" v-if="!bianjike">{{
                        $t("menu.exception.trigger")
                      }}</a-button>
                    </a-popconfirm>
                  </a-space>
                </span>
              </template>
            </a-table-column>
          </a-table>
        </template>
        <!--任务名称----------------------->
        <a-table-column
          key="DpiaName"
          :title="$t('menu.form.step-form.info')"
          @filterDropdownVisibleChange="
            (e) => {
              if (e) this.setValus(1);
            }
          "
        >
          <template slot-scope="record">
            {{ record.DpiaName ? record.DpiaName : record.RiskName }}
          </template>
          <!-- <span slot="title" class="min-w-90p">{{ $t('menu.form.step-form.info') }}</span> -->
          <span
            slot="filterDropdown"
            slot-scope="{
              setSelectedKeys,
              selectedKeys,
              confirm,
              clearFilters,
              column,
            }"
          >
            <table-select
              ref="tableselect1"
              :filter-data="filterData"
              @searchCommit="searchQuery"
              @searchFilter="searchQueryFilter"
              @searchClose="confirm"
              @searchClean="tableCleanJobs"
            />
          </span>
        </a-table-column>
        <!-- 任务类型------------------->
        <a-table-column
          key="TaskType"
          data-index="TaskType"
          width="120px"
          @filterDropdownVisibleChange="
            (e) => {
              if (e) this.setValus(2);
            }
          "
        >
          <span slot="title" class="min-w-90p">{{
            $t("menu.form.step-form.confirm")
          }}</span>
          <span
            slot="filterDropdown"
            slot-scope="{
              setSelectedKeys,
              selectedKeys,
              confirm,
              clearFilters,
              column,
            }"
          >
            <table-select
              ref="tableselect2"
              :single-search="false"
              :filter-data="filterData"
              @searchCommit="searchQuery"
              @searchFilter="searchQueryFilter"
              @searchClose="confirm"
              @searchClean="tableCleanJobs"
            />
          </span>
        </a-table-column>
        <!-- 任务负责人------------------- -->
        <a-table-column
          key="DpiaDco"
          width="120px"
          :title="$t('menu.form.step-form.result')"
          @filterDropdownVisibleChange="
            (e) => {
              if (e) this.setValus(3);
            }
          "
        >
          <template slot-scope="record">
            {{ record.DpiaDco ? record.DpiaDco : record.RiskOwnerUserName }}
          </template>
          <!--          <span slot="title" class="min-w-90p">{{ $t('menu.form.step-form.result') }}</span>-->
          <span
            slot="filterDropdown"
            slot-scope="{
              setSelectedKeys,
              selectedKeys,
              confirm,
              clearFilters,
              column,
            }"
          >
            <table-select
              ref="tableselect3"
              :filter-data="filterData"
              @searchCommit="searchQuery"
              @searchFilter="searchQueryFilter"
              @searchClose="confirm"
              @searchClean="tableCleanJobs"
            />
          </span>
        </a-table-column>
        <!-- 发起人 -->
        <a-table-column key="TaskCreator" data-index="TaskCreator" width="120px" @filterDropdownVisibleChange="(e) => {
            if (e) this.setValus(7);
          }
          ">
          <span slot="title">{{ $t("menu.form.advanced.creator") }}</span>
          <span slot="filterDropdown" slot-scope="{
              setSelectedKeys,
              selectedKeys,
              confirm,
              clearFilters,
              column,
            }">
            <table-select ref="tableselect7" :single-search="false" :filter-data="filterData" @searchCommit="searchQuery"
              @searchFilter="searchQueryFilter" @searchClose="confirm" @searchClean="tableCleanJobs" />
          </span>
        </a-table-column>
        <!-- 发起时间 ----------------------------->
        <a-table-column
          key="DpiaCreateTime"
          data-index="CreateTime"
          width="180px"
          @filterDropdownVisibleChange="
            (e) => {
              if (e) this.setValus(4);
            }
          "
        >
          <span slot="title">{{ $t("menu.form.advanced-form") }}</span>
          <span
            slot="filterDropdown"
            slot-scope="{
              setSelectedKeys,
              selectedKeys,
              confirm,
              clearFilters,
              column,
            }"
          >
            <table-select
              ref="tableselect4"
              :single-search="false"
              :filter-data="filterData"
              @searchCommit="searchQuery"
              @searchFilter="searchQueryFilter"
              @searchClose="confirm"
              @searchClean="tableCleanJobs"
            />
          </span>
        </a-table-column>
        <!-- <a-table-column key="TaskEndTime" data-index="TaskEndTime" width="150" >
            <span slot="title" >{{ $t('menu.list') }}</span>
          </a-table-column> -->
        <!-- 状态------------------------->
        <a-table-column
          key="DpiaStatus"
          data-index="DpiaStatus"
          width="160px"
          @filterDropdownVisibleChange="
            (e) => {
              if (e) this.setValus(5);
            }
          "
        >
          <span slot="title">{{ $t("menu.list.table-list") }}</span>
          <span
            slot="filterDropdown"
            slot-scope="{
              setSelectedKeys,
              selectedKeys,
              confirm,
              clearFilters,
              column,
            }"
          >
            <table-select
              ref="tableselect5"
              :single-search="false"
              :filter-data="filterData"
              @searchCommit="searchQuery"
              @searchFilter="searchQueryFilter"
              @searchClose="confirm"
              @searchClean="tableCleanJobs"
            />
          </span>
          <template slot-scope="text, record">
            <div v-if="record.DpiaStatus == 1 || record.RiskState == 1">
              <a-badge color="blue" />
              {{ $t("user.verification-code.required111566133") }}
            </div>
            <div v-else-if="record.DpiaStatus == 2 || record.RiskState == 2">
              <a-badge color="orange" />
              {{ $t("user.verification-code.required1115661444444") }}
            </div>
            <div v-else-if="record.DpiaStatus == 3 || record.RiskState == 3">
              <a-badge color="purple" />
              {{ $t("user.verification-code.required111566145") }}
            </div>
            <div v-else-if="record.DpiaStatus == 4 || record.RiskState == 4">
              <a-badge color="orange" />
              {{ $t("user.verification-code.required111566146") }}
            </div>
            <div v-else-if="record.DpiaStatus == 5 || record.RiskState == 5">
              <span v-if="record.TaskType == 'Risk'">
                <a-badge color="gray" />
                {{
                  $t(
                    "user.verification-code.required111566110577371442281431222335566555555"
                  )
                }}</span
              >
              <span v-if="record.TaskType == 'DPIA'">
                <a-badge color="gray" />
                {{ $t("user.verification-code.required1115661222222") }}</span
              >
            </div>
          </template>
        </a-table-column>
        <!-- 更新时间------------------ -->
        <a-table-column
          key="DpiaUpdatetime"
          data-index="Updatetime"
          width="180px"
          @filterDropdownVisibleChange="
            (e) => {
              if (e) this.setValus(6);
            }
          "
        >
          <span slot="title">{{ $t("menu.list.basic-list") }}</span>
          <!--          <template slot-scope="text, record">-->
          <!--            <span>{{-->
          <!--                record.Updatetime ? record.Updatetime : record.CreateTime-->
          <!--              }}</span>-->
          <!--          </template>-->
          <span
            slot="filterDropdown"
            slot-scope="{
              setSelectedKeys,
              selectedKeys,
              confirm,
              clearFilters,
              column,
            }"
          >
            <table-select
              ref="tableselect6"
              :single-search="false"
              :filter-data="filterData"
              @searchCommit="searchQuery"
              @searchFilter="searchQueryFilter"
              @searchClose="confirm"
              @searchClean="tableCleanJobs"
            />
          </span>
        </a-table-column>
        <!-- 操作 -->
        <a-table-column
          key="action"
          :title="$t('app.setting.othersettings')"
          width="80px"
        >
          <template slot-scope="text, record">
            <div v-if="record.DpiaName">
              <a-button
                type="link"
                @click="go(record)"
                v-if="
                  (((record.DpiaDcoUserId == userId &&
                    record.DpiaStatus != 1) ||
                    (record.DpiaCreateUser == userId &&
                      (record.DpiaStatus == 1 || record.DpiaStatus == 2))) &&
                    record.DpiaStatus != 5 &&
                    record.DpiaStatus != 4) ||
                  ((pageState == 1 || pageState == 2) &&
                    (record.DpiaStatus == 1 || record.DpiaStatus == 2))
                "
              >
                {{ $t("user.v160") }}
              </a-button>

              <span v-else>
                <a-dropdown>
                  <a-button type="link" v-if="record.DpiaStatus !== 5">
                    <a-icon type="more" />
                  </a-button>
                  <template #overlay>
                    <a-menu>
                      <!-- 去答题按钮 -->
                      <a-menu-item
                        v-if="
                          record.DpiaStatus === 1 &&
                          (record.Role.CREATE == 1 ||
                            record.Role.WRITE == 1 ||
                            record.Role.View == 1)
                        "
                        @click="edit(record)"
                      >
                        <a-button type="link">{{
                          $t("user.verification-code.required1115661105717")
                        }}</a-button>
                      </a-menu-item>
                      <!-- 删除按钮 -->
                      <a-menu-item
                        v-if="
                          record.DpiaStatus === 1 && record.Role.CREATE == 1
                        "
                      >
                        <a-popconfirm
                          :title="
                            $t('user.verification-code.required111566110577225')
                          "
                          :ok-text="$t('user.verification-code.required1166')"
                          :cancel-text="$t('user.email.required11')"
                          @confirm="() => del(record.Id)"
                        >
                          <a-button
                            type="link"
                            style="width: 100%; text-align: left"
                            >{{ $t("menu.exception.trigger") }}</a-button
                          >
                        </a-popconfirm>
                      </a-menu-item>
                      <!-- 撤回 -->
                      <a-menu-item
                        v-if="
                          record.IsDcoState == 0 &&
                          record.Role.CREATE == 1 &&
                          record.DpiaStatus == 2 &&
                          (record.DpiaChangeDcoId !=
                            $store.state.user.info.YtId ||
                            record.DpiaChangeDcoId == '')
                        "
                      >
                        <a-popconfirm
                          :title="
                            $t(
                              'user.verification-code.required11156611057737144228'
                            )
                          "
                          :ok-text="
                            $t('user.verification-code.required1166888')
                          "
                          :cancel-text="$t('user.email.required11')"
                          @confirm="() => withdraw(record)"
                        >
                          <a-button
                            style="width: 100%; text-align: left"
                            type="link"
                            >{{
                              $t(
                                "user.verification-code.required11156611057737144227"
                              )
                            }}</a-button
                          >
                        </a-popconfirm>
                      </a-menu-item>
                      <!-- 下载 -->
                      <a-menu-item
                        v-if="
                          record.Reports === 1 &&
                          record.RpaIfCompletedPIA === 0 &&
                          record.RpaNoPIOrImportantInvolved == 0 &&
                          (record.DpiaChangeDcoId !=
                            $store.state.user.info.YtId ||
                            record.DpiaChangeDcoId == '')
                        "
                      >
                        <a-button type="link" @click="xiazai(record)">{{
                          $t("user.verification-code.required1115661105715")
                        }}</a-button>
                      </a-menu-item>
                      <!-- 查看 -->
                      <a-menu-item
                        v-if="
                          record.DpiaStatus === 2 ||
                          (ifAllTask === true &&
                            (record.DpiaStatus === 2 ||
                              record.DpiaStatus === 3))
                        "
                        @click="review(record)"
                      >
                        <a-button type="link">{{
                          $t("user.verification-code.required1115661105718")
                        }}</a-button>
                      </a-menu-item>
                      <!-- 评估 -->
                      <a-menu-item
                        v-if="
                          (record.DpiaStatus === 2 &&
                            record.ReviewStatus === 1) ||
                          record.Role.CHANGE
                        "
                        @click="estimate(record)"
                      >
                        <a-button type="link">{{
                          $t("user.verification-code.required1115661105719")
                        }}</a-button>
                      </a-menu-item>
                      <!-- 整体评估 -->
                      <a-menu-item
                        v-if="
                          (record.DpiaStatus === 3 &&
                            record.Role.DCO == 1 &&
                            (record.DpiaChangeDcoId !=
                              $store.state.user.info.YtId ||
                              record.DpiaChangeDcoId == '')) ||
                          record.Reports === 1
                        "
                        @click="
                          record.DpiaStatus === 3
                            ? overall(record, 'allReview')
                            : overall(record, 'see')
                        "
                      >
                        <a-button type="link">{{
                          record.DpiaStatus === 3
                            ? $t("user.verification-code.required1115661105720")
                            : $t("user.verification-code.required1115661105718")
                        }}</a-button>
                      </a-menu-item>
                      <!-- 终止 -->
                      <a-menu-item
                        v-if="
                          (record.DpiaStatus === 2 ||
                            record.DpiaStatus === 3) &&
                          record.Role.CREATE == 1
                        "
                      >
                        <a-popconfirm
                          :title="
                            $t('user.verification-code.required111566110577314')
                          "
                          :ok-text="$t('user.verification-code.required1166')"
                          :cancel-text="$t('user.email.required11')"
                          @confirm="() => stop(record)"
                        >
                          <a-button type="link">{{
                            $t("user.verification-code.required1115661105721")
                          }}</a-button>
                        </a-popconfirm>
                      </a-menu-item>
                      <!-- 多人答题 -->
                      <a-menu-item
                        v-if="
                          record.DpiaStatus != 5 &&
                          record.Role.CREATE == 1 &&
                          record.DpiaStatus === 1 &&
                          record.RpaIfCompletedPIA == 0 &&
                          record.RpaNoPIOrImportantInvolved == 0
                        "
                        @click="showPermissions(record, 'write')"
                      >
                        <a-button type="link">
                          {{ $t("user.v17") }}
                        </a-button>
                      </a-menu-item>
                      <!-- 共享权限 -->
                      <a-menu-item
                        v-if="
                          record.DpiaStatus != 5 &&
                          record.Role.CREATE == 1 &&
                          record.DpiaStatus != 1
                        "
                        @click="showPermissions(record)"
                      >
                        <a-button type="link">{{
                          $t("user.verification-code.required1115661105722")
                        }}</a-button>
                      </a-menu-item>
                    </a-menu>
                  </template>
                </a-dropdown>
                <Permissions ref="Permissions"></Permissions>
              </span>
            </div>
            <div v-if="!record.DpiaName">
              <a-button
                type="link"
                @click="riskEdit((mode = 1), record, editId)"
                v-if="
                  (record.RiskOwnerUserId == userId &&
                    record.DpiaStatus == 3 &&
                    record.DpiaStatus != 4) ||
                  ((pageState == 1 || pageState == 2) &&
                    record.DpiaStatus != 4 &&
                    record.RiskState == 3 &&
                    record.RiskOwnerUserId === userId) ||
                  (record.RiskState == 1 && record.RiskCreateUserId == userId)
                "
              >
                {{ $t("user.v160") }}
              </a-button>
            </div>
            <div v-if="!record.DpiaName">
              {{ record.DpiaStatus }}
              <a-button
                type="link"
                @click="showReview('2', record.Id)"
                v-if="
                  (record.RiskDcoUserId == userId &&
                    record.DpiaStatus == 2 &&
                    record.DpiaStatus != 4) ||
                  ((pageState == 1 || pageState == 2) &&
                    record.DpiaStatus != 4 &&
                    record.RiskState == 2)
                "
              >
                {{ $t("user.v160") }}
              </a-button>
            </div>
          </template>
        </a-table-column>

      </a-table>
      <createRisk
        ref="createRisk"
        @succeed="getList"
        @initEditId="initEditId"
        @getList="getList"
        :userList="userList"
        :riskLevel="riskLevel"
        :riskType="riskType"
        :editId="editId"
        :mode="mode"
      />
      <riskReview
        ref="riskReview"
        :userList="userList"
        :riskLevel="riskLevel"
        :riskType="riskType"
        :editId="editId"
      ></riskReview>
      <!-- 分页 -->
      <a-pagination
        size="small"
        v-model="pagination.page"
        :total="pagination.total"
        hideOnSinglePage
        :pageSize.sync="pagination.pageSize"
        @change="getList"
      />

      <!-- 查看匹配数据 -->
      <a-modal
        :title="detailTitle"
        :visible="eyeDrawer"
        width="750px"
        @cancel="closeEyeDrawer"
      >
        <a-table
          style="width: 700px"
          :data-source="eyeDrawerList"
          bordered
          :rowKey="(record) => record.Id"
        >
          <!-- 创建时间 -->
          <a-table-column
            key="DpiaReportCreatetime"
            :title="$t('user.verification-code.required111566131')"
            data-index="DpiaReportCreatetime"
          />
          <!-- 报告地址 -->
          <a-table-column
            key="DpiaReportAddress"
            :title="$t('user.verification-code.required11156613122')"
            data-index="DpiaReportAddress"
          >
            <template slot-scope="text, record">
              <span>
                <a @click="axia(record)">{{ record.urlAll }}</a>
              </span>
            </template>
          </a-table-column>
        </a-table>
        <!-- 按钮配置 -->
        <template slot="footer">
          <!-- 关闭 -->
          <a-button type="primary" @click="closeEyeDrawer">
            {{ $t("app.setting.themecolor.ff99999999") }}
          </a-button>
        </template>
      </a-modal>
    </a-card>
  </div>
</template>

<script>
import menutabs from "@/mixins/menu-mixin";
import { taskListNew } from "@/api/ytdg";
import { configurationSelect } from "@/api/configs";
import form from "@/locales/lang/zh-CN/form";
import { getUserList, userQuery } from "@/api/common/form";
import creatRiskAction from "./creatRiskAction.vue";
import Permissions from "../dataAssessment/components/Permissions.vue";

import {
  riskDetail,
  RISKEditActionList,
  ristCreateAction,
  ristDelAction,
  taskSelect,
} from "@/api/risk/form";
import createRisk from "../risk/components/createRisk.vue";
import riskReview from "@/views/risk/components/riskReview.vue";
import tableSelect from "@/components/tableSelect/tableSelect.vue";
import {
  dpiaWithdraw,
  rickActiondel,
  dpiaChangeState,
  isWithdraw,
  dpiaDelete,
  DpiaList,
} from "@/api/dpia/form";
export default {
  name: "myTasks",
  components: {
    creatRiskAction,
    createRisk,
    riskReview,
    tableSelect,
    Permissions,
  },
  mixins: [menutabs],
  data() {
    return {
      menuKey: [1],
      itemkey: 0,
      expandedRowKeys: [], // 扩展行的行键列表
      listData: [],
      riskList: [],
      userList: [],
      riskLevel: [],
      riskType: [],
      eyeDrawer: false,
      eyeDrawerList: [], // 眼睛弹窗列表
      detailTitle: "",
      queryForm: {
        // page: 1, //当前页
        // pageSize: 10,
        Name: undefined,
        types: 1,
        taskType: undefined,
        Owner: undefined,
        TaskState: undefined,
      },
      listLoading: false,

      // 状态下拉
      statusList: [
        {
          label: "user.verification-code.required111566133",
          value: 1,
        },
        {
          label: "user.verification-code.required111566145",
          value: 3,
        },
        {
          label: "user.verification-code.required111566146",
          value: 4,
        },
        {
          label:
            "user.verification-code.required11156611057737144228143122233556655",
          value: 5,
        },
      ],
      // 分页参数
      pagination: {
        page: 1, //当前页
        pageSize: 10, //每页条数
        total: 0, //总条数
        showQuickJumper: true,
        hideOnSinglePage: true,
      },
      mode: "",
      riskId: 0,
      editId: 0,
      tabTotal: {
        0: 0,
        1: 0,
        2: 0,
      },
      userId: this.$store.state.user.info.userid,
      //顶部路由状态
      pageState: 1,
      YtAdminName: "", //存入的用户ID
      setValusKey: "",
      //搜索
      okyMap: [
        "",
        "Name",
        "taskType",
        "Owner",
        "DpiaCreatetime",
        "DpiaStatus",
        "DpiaUpdatetime",
        "TaskCreator",
      ],
      //筛选
      kvMap: [
        "",
        "DpiaName",
        "TaskType",
        "DpiaDco",
        "DpiaCreatetime",
        "DpiaStatus",
        "DpiaUpdatetime",
        "TaskCreator",
      ],
      ifAllTask: false,
      lang: 'zh-EN',
      record1:'',
      expanded1:'',
      isLable : 0,
    };
  },

  async created() {
    if (
      this.$store.state.user.info.role.includes("35") ||
      this.$store.state.user.info.role.includes("36")
    ) {
      this.ifAllTask = true;
    }
    await this.getList();
    for (let i = 0; i < 3; i++) {
      const { data } = await taskListNew({
        page: 1,
        pageSize: 1,
        types: i + 1,
      });
      // console.log("初始", i, "：：：：：：：：：：：：", data);
      // 解构赋值
      const { Total } = data;
      this.tabTotal[i] = Total;
    }
    
  },
  mounted() {
    const nowLang =  localStorage.getItem("lang").includes("zh-EN")
    if( nowLang ) {
      this.lang = 'zh-EN'
    }else{
      this.lang = 'zh-CN'
    }
    window.addEventListener('setItemEvent',  (e)=> {
      if (e.key == 'lang') {
        this.lang = JSON.parse(e.value)
      }
    })
  },
  methods: {
    async filte1rOption(value) {
      // console.log(value);
      this.inputValue = value;
      const { data } = await getUserList({
        UserEmail: value,
        UserName: value,
      });
      this.userList = data;
    },
    onChange(e) {
      // console.log(e);
      this.YtAdminName = e;
    },
    // async getList1() {
    //   console.log("获取列表");
    //   await this.getRiskList();
    //   this.listLoading = true;
    //   const { page, pageSize } = this.pagination;
    //   console.log("this.pagination", this.pagination.page);
    //   try {
    //     if (this.itemkey === 0) {
    //       // 调用查询列表
    //       console.log("--------------", this.taskType);
    //       const { data } = await taskListNew({
    //         ...{ page: page, pageSize },
    //         ...(this.queryForm = {
    //           Name: undefined,
    //           types: this.itemkey + 1,

    //           taskType: undefined,
    //           Owner: undefined,
    //           TaskState: undefined,
    //           YtAdminName: this.YtAdminName,
    //         }),
    //       });
    //       // 解构赋值
    //       const { Page, PageSize, Total, Lists } = data;

    //       // 给table赋值
    //       this.listData = Lists || [];
    //       // 给分页数据赋值
    //       this.pagination = {
    //         page: Page,
    //         pageSize: PageSize,
    //         total: Total,
    //       };
    //       this.tabTotal[this.queryForm.TaskDistinguish] = Total;
    //     } else {
    //       // 调用查询列表
    //       const { data } = await taskListNew({
    //         ...{ page: page, pageSize },
    //         ...(this.queryForm = {
    //           Name: undefined,
    //           types: this.itemkey,
    //           taskType: undefined,
    //           Owner: undefined,
    //           TaskState: undefined,
    //         }),
    //       });
    //       // 解构赋值
    //       const { Page, PageSize, Total, Lists } = data;

    //       // 给table赋值
    //       this.listData = Lists || [];
    //       // 给分页数据赋值
    //       this.pagination = {
    //         page: Page,
    //         pageSize: PageSize,
    //         total: Total,
    //       };
    //       this.tabTotal[this.queryForm.TaskDistinguish] = Total;
    //     }

    //     // console.log('data3456', data);

    //     // 获取用户列表下拉
    //     const { data: userList } = await userQuery(1);
    //     this.userList = userList;
    //   } catch (error) {
    //     // 报错信息
    //     this.$message.error(error);
    //     console.log(error);
    //   } finally {
    //     // 不管成功失败都会执行
    //     this.listLoading = false;
    //   }
    // },
    initEditId() {
      this.editId = 0;
    },
    async getList(state) {
      // await this.getRiskList();
      this.listLoading = true;
      const { page, pageSize } = this.pagination;
      console.log("this.pagination", this.pagination.page);
      try {
        
        // 调用查询列表
        const { data } = await taskListNew({
          ...{ page: state === "filter" ? 1 : page, pageSize },
          ...this.queryForm,
        });
        // 获取用户列表下拉
        //  const { data: userList1 } = await userQuery(1);
        //     this.userList1 = userList1
        // console.log('data3456', data);
        // 解构赋值
        const { Page, PageSize, Total, Lists } = data;

        // 给table赋值
        this.listData = Lists || [];
        // console.log("listData", this.listData);
        // 给分页数据赋值
        this.pagination = {
          page: Page,
          pageSize: PageSize,
          total: Total,
        };
        this.tabTotal[this.queryForm.TaskDistinguish] = Total;
        // 获取用户列表下拉

        const { data: userList } = await userQuery(1);
        this.userList = userList;
        //初始风险等级
        const { data: riskLevel } = await configurationSelect({ state: 8 });
        this.riskLevel = riskLevel;

        //风险类型
        const { data: riskType } = await configurationSelect({ state: 9 });
        this.riskType = riskType;
        
        await this.getRiskList(this.expanded1,this.listData.find(item=>item.Id==this.expandedRowKeys))
        
      } catch (error) {
        // 报错信息
        this.$message.error(error);
        console.log(error);
      } finally {
        // 不管成功失败都会执行
        this.listLoading = false;
      }
    },
    // 去操作
    go(record) {
      if (record.DpiaStatus == 1) {
        this.$router.push({ path: "/dpia/question", query: { id: record.Id } });
      } else if (record.DpiaStatus == 2) {
        this.$router.push({
          path: "/dpia/onequestion/estimate",
          query: {
            ...record,
            id: record.Id,
            ChangeCommit: record.CHANGE,
            ifDco: record.DpiaDcoUserId === this.userId ? 1 : 0,
            DpiaCreateUserId: record.DpiaCreateUser,
            DpiaChangeDcoId: record.DpiaChangeDcoId || "",
            DpiaId: record.DpiaId,
          },
        });
      } else {
        this.$router.push({
          path: "/dpia/onequestion/overall",
          query: { ...record, id: record.Id ,isLable: this.isLable},
        });
      }
    },
    async riskEdit(mode = 1, record, edited) {
      const { data } = await riskDetail({ Id: record.Id });
      if (
        record.RiskState == 3 &&
        record.RiskDcoUserId === this.$store.state.user.info.userid &&
        record.RiskOwnerUserId !== this.$store.state.user.info.userid
      ) {
        mode = 2;
      }
      this.$refs.createRisk.open(
        mode,
        { ...data, RiskOwnerUserId: record.RiskOwnerUserId },
        record.Id
      );
    },
    handleClickMenu(item) {
      this.pageState = item.key;
      // console.log("-------------------", item);
      if (item.key === 2) {
        this.isLable = 0
      }else if (item.key === 3) {
        this.isLable = 1
      }
      this.queryForm = {}
      this.queryForm.types = item.key;
      this.itemkey = item.key;
      this.getList();
      this.getList1();
    },
    // action 修改按钮
    async showModal(state, editId, mode, record) {
      if (state === "0") {
        //新建时获取actin ID
        const { data } = await ristCreateAction();
        //  console.log(data.ActionId);
        this.$refs.creatRiskAction.openAction(data);
      } else {
        //编辑
        try {
          // console.log(editId);
          const { data } = await RISKEditActionList({ Id: editId });
          //传值回显
          let allDetails = this.listData.filter((item) => {
            return (
              item.Id === (mode === "DPIA" ? record.DpiaQid : record.RiskId)
            );
          })[0];
          this.$refs.creatRiskAction.openAction(
            editId,
            data,
            allDetails.RiskOwnerUserId === this.$store.state.user.info.userid
              ? ""
              : allDetails[mode === "DPIA" ? "DpiaStatus" : "RiskState"] ===
                  4 ||
                this.$store.state.user.info.userid === record.DpiaActionUserId
              ? "see"
              : ""
          );
        } catch (error) {
          // 报错信息
          this.$message.error(error);
          console.log(error);
        } finally {
          // 不管成功失败都会执行
          this.listLoading = false;
          
        }
      }
    },
    // 去答题
    edit(record) {
      // console.log('===> ', record)
      if (record.RpaIfCompletedPIA == 1) {
        this.$router.push({
          path: "/dpia/RpaIfCompletedPIA",
          query: { id: record.Id },
        });
      } else if (record.RpaNoPIOrImportantInvolved == 1) {
        this.$router.push({
          path: "/dpia/RpaNoPIOrImportantInvolved",
          query: { id: record.Id },
        });
      } else {
        this.$router.push({ path: "/dpia/question", query: { id: record.Id } });
      }
    },
    //撤回
    async withdraw(e) {
      try {
        // console.log(e)
        await dpiaWithdraw({ Id: e.Id })
        this.init()
      } catch (err) {
        this.$message.error(err);
        console.log(err);
      }
    },
    // 删除
    // async del(record) {
    //   this.listLoading = true;
    //   try {
    //     console.log(record);
    //     await ristDelAction({ Id: record.Id });
    //     this.$message.success(
    //       this.$t("user.verification-code.required111566110577133")
    //     );
    //     this.getList(record.RiskId);
    //   } catch (error) {
    //     // 报错信息
    //     this.$message.error(error);
    //   } finally {
    //     // 不管成功失败都会执行
    //     this.listLoading = false;
    //   }
    // },
    async del(id) {
      try {
        // 传过来的id直接请求删除api
        await dpiaDelete({ Id: id });
        this.$message.success(
          this.$t("user.verification-code.required111566110577210")
        );
        // 重新初始化列表刷新数据
        this.init();
      } catch (error) {
        this.$message.error(error);
      } finally {
      }
    },
    async init() {
      this.pagination.current = 1;
      this.getList();
    },
    //终止
    async stop(record) {
      await dpiaChangeState({ Id: record.Id, DpiaStatus: 5 });
      this.getList();
    },
     //下载
     async xiazai(record) {
      const { data } = await DpiaList({ Id: record.Id })
      const urls = data.Lists.map(item => item.DpiaReportAddress);
      // console.log(urls);

      if(this.lang === 'zh-EN') {
          const enUrls = urls.filter(url => url.includes('en'));
          sessionStorage.setItem('report',enUrls)
          this.$router.push({
            path: '/task/report',
          })
      }else {
          const cnUrls = urls.filter(url => !url.includes('en'));
          sessionStorage.setItem('report',cnUrls)
          this.$router.push({
            path: '/task/report',
          })
      }
    },
    //下载报告
    // async axia(data) {
    //   window.open(data.urlAll, 'blank')
    // },
    // closeEyeDrawer() {
    //   this.eyeDrawer = false
    // },
    // 评估
    async estimate(record) {
    const res = await isWithdraw({ Id: record.Id })
    // console.log(res)
    if (res.data == 0) {
      this.$message.error('不可评估')
      return
    }
    if (record.RpaIfCompletedPIA == 1) {
      // DCO评估
      this.$router.push({
        path: '/dpia/onequestion/estimatePIA',
        query: {
          ...record,
          id: record.Id,
          DpiaCreateUserId: record.DpiaCreateUserId,
          DpiaChangeDcoId: record.DpiaChangeDcoId || '',
          DpiaId: record.DpiaId,
          ChangeCommit: record.Role.CHANGE,
          ifDco: record.Role.DCO,
        },
      })
      localStorage.setItem('ifchaning', true)
    } else if (record.RpaNoPIOrImportantInvolved == 1) {
      // DCO评估
      this.$router.push({
        path: '/dpia/onequestion/estimatlvede',
        query: {
          ...record,
          id: record.Id,
          DpiaCreateUserId: record.DpiaCreateUserId,
          DpiaChangeDcoId: record.DpiaChangeDcoId || '',
          DpiaId: record.DpiaId,
          ChangeCommit: record.Role.CHANGE,
          ifDco: record.Role.DCO,
        },
      })
      localStorage.setItem('ifchaning', true)
    } else {
      // DCO评估
      this.$router.push({
        path: '/dpia/onequestion/estimate',
        query: {
          ...record,
          id: record.Id,
          DpiaCreateUserId: record.DpiaCreateUserId,
          DpiaChangeDcoId: record.DpiaChangeDcoId || '',
          DpiaId: record.DpiaId,
          ChangeCommit: record.Role.CHANGE,
          ifDco: record.Role.DCO,
        },
      })
      localStorage.setItem('ifchaning', true)
    }

    },
    // 整体评估
    overall(record, state) {
      if (record.RpaIfCompletedPIA == 1) {
        this.$router.push({
          path: "/dpia/onequestion/overallPIa",
          query: { id: record.Id, state: state },
        });
      } else if (record.RpaNoPIOrImportantInvolved == 1) {
        this.$router.push({
          path: "/dpia/onequestion/overallvede",
          query: { id: record.Id, state: state },
        });
      } else {
        this.$router.push({
          path: "/dpia/onequestion/overall",
          query: { id: record.Id, state: state , isLable: this.isLable },
        });
      }
    },
    // 答题后的查看
    review(record) {
      if (record.RpaIfCompletedPIA == 1) {
        this.$router.push({
          path: "/dpia/onequestion/reviewPIA",
          query: { id: record.Id },
        });
      } else if (record.RpaNoPIOrImportantInvolved == 1) {
        this.$router.push({
          path: "/dpia/onequestion/reviewlved",
          query: { id: record.Id },
        });
      } else {
        this.$router.push({
          path: "/dpia/onequestion/review",
          query: { id: record.Id },
        });
      }
    },
    // 多人答题 共享权限
    showPermissions(data, state) {
      //展开可读权限
      this.$refs.Permissions.open(data, state);
    },

    restQuery() {
      this.queryForm.TaskName = undefined;
      this.queryForm.TaskType = undefined;
      this.queryForm.TaskLiable = undefined;
      this.queryForm.TaskState = undefined;
      this.getList();
    },
    filterOption(input, option) {
      // console.log(input);
      return (
        option.componentOptions.children[0].text
          .toLowerCase()
          .indexOf(input.toLowerCase()) >= 0
      );
    },
    search() {
      this.pagination.page = 1;
      this.getList();
      // console.log("form", form);
    },
    // 分页事件 直接复制使用 通用的
    tableChange(pagination) {
      this.pagination = pagination;
      this.getList();
    },
    async getRiskList(expanded, record) {
      console.log("record", record);
      console.log("expanded", expanded);
      if (expanded) {
        this.record1 = record
        this.expanded1 = expanded 
        const arr = [];
        // 当某一行展开时，关闭其他行
        console.log('record.Id]',record.Id);
        this.expandedRowKeys = [record.Id];
        const dataList1 = record.child;
        if (dataList1) {
          dataList1.forEach((item) => {
            item.state = record.TaskType;
            arr.push(item);
          });
        }
        this.riskList = arr;
        console.log("this.riskList", this.riskList);

      } else {
        // 当某一行关闭时，清空展开行键列表
        // this.expandedRowKeys = [];

      }
    },
    async showReview(state, editId) {
      try {
        this.editId = editId;
        this.mode = state;
        //回显传值
        const { data } = await riskDetail({ Id: editId });
        await this.$refs.riskReview.open(state, data, this.editId);
      } catch (error) {
        // 报错信息
        this.$message.error(error);
      } finally {
        // 不管成功失败都会执行
        this.listLoading = false;
      }
    },

    // 查询Filter逻辑
    async setValus(typeId) {
      this.listLoading = true;
      try {
        // 调用查询列表
        const { data } = await taskSelect({
          Types: typeId,
          types: this.itemkey ? this.itemkey : 1,
        });
        for (let j = 0; j < data.length; j++) {
          if (typeId === 5) {
            switch (data[j].value) {
              case 1:
                data[j].text = this.$t(
                  "user.verification-code.required111566133"
                );
                break;
              case 2:
                data[j].text = this.$t(
                  "user.verification-code.required1115661444444"
                );
                break;
              case 3:
                data[j].text = this.$t(
                  "user.verification-code.required111566145"
                );
                break;
              case 4:
                data[j].text = this.$t(
                  "user.verification-code.required111566146"
                );
                break;
              case 5:
                data[j].text = `${this.$t(
                  "user.verification-code.required111566110577371442281431222335566555555"
                )}/${this.$t("user.verification-code.required1115661222222")}`;
                break;
              default:
                break;
            }
          } else {
            data[j].text = data[j].value;
          }
        }
        this.setValusKey = typeId;
        this.filterData = data;
      } catch (error) {
        // 报错信息
        this.$message.error(error);
        console.log(error);
      } finally {
        // 不管成功失败都会执行
        this.listLoading = false;
      }
    },
    async searchQuery(e) {
      this.queryForm[this.kvMap[this.setValusKey]] = undefined;
      this.queryForm = {
        ...this.queryForm,
        [this.okyMap[this.setValusKey]]:
          this.setValusKey === 2 ? (e === "Risk" ? 2 : 1) : e,
      };
      await this.getList("filter");
    },
    async searchQueryFilter(e) {
      this.queryForm[this.okyMap[this.setValusKey]] = undefined;
      this.queryForm = {
        ...this.queryForm,
        [this.kvMap[this.setValusKey]]:
          this.setValusKey === 1
            ? e.replaceAll("/", "#@%$")
            : this.setValusKey === 2
            ? e === "Risk"
              ? 2
              : e === "DPIA"
              ? 1
              : "1,2"
            : e,
      };
      await this.getList("filter");
    },
    async tableCleanJobs(type) {
      this.pagination.page = 1;
      if (type === "part") {
        this.queryForm[this.kvMap[this.setValusKey]] = undefined;
        this.queryForm[this.okyMap[this.setValusKey]] = undefined;
      } else {
        this.queryForm = {
          types: this.itemkey ? this.itemkey : 1,
        };
        for (let i = 1; i <= 6; i++) {
          let dom = this.$refs[`tableselect${i}`];
          if (dom) {
            dom.inputValue = "";
            dom.inputCheckValue = [];
          }
        }
      }
      this.inputValue = "";
      await this.getList();
    },
    //删除action
    async delActions(id) {
      //调接口
      try {
        // 传过来的id直接请求删除api
        await rickActiondel({ Id: id });
        this.getList();
        this.$message.success(
          this.$t("user.verification-code.required111566110577133")
        );
      } catch (error) {
        this.$message.error(error);
      } finally {
      }
    },
    createActions(precord) {
      // 创建Action
      this.id = precord.Id;
      this.$refs.createAction.open();
    },
  },
};
</script>
<style lang="less" scoped>
/deep/ .ant-table-thead {
  background: #f4f7ff;
  font-weight: 700;
}

.ant-pagination {
  float: right;
}
</style>